﻿using System;
using System.Collections.Generic;

namespace TetrisGame
{
    internal class BlockInfo
    {
        private readonly List<Position[]> bolcks = new List<Position[]>(); // 方块坐标信息列表

        // 通过构造函数初始化方块坐标信息
        public BlockInfo(E_DrawType blockType)
        {
            switch (blockType)
            {
                // 正方形
                case E_DrawType.Block:
                    bolcks.Add(new Position[] { new Position(2, 0), new Position(0, 1), new Position(2, 1) });
                    break;
                // 长条形
                case E_DrawType.Line:
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(0, -2), new Position(0, -3) });
                    bolcks.Add(new Position[] { new Position(-4, 0), new Position(-2, 0), new Position(2, 0) });
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(0, -2), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(-2, 0), new Position(2, 0), new Position(4, 0) });
                    break;
                // T形
                case E_DrawType.TShape:
                    bolcks.Add(new Position[] { new Position(-2, 0), new Position(2, 0), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(-2, 0), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(-2, 0), new Position(2, 0) });
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(2, 0), new Position(0, 1) });
                    break;
                // 左Z形
                case E_DrawType.Left_ZShape:
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(-2, 0), new Position(-2, 1) });
                    bolcks.Add(new Position[] { new Position(-2, -1), new Position(0, -1), new Position(2, 0) });
                    bolcks.Add(new Position[] { new Position(2, -1), new Position(2, 0), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(-2, 0), new Position(0, 1), new Position(2, 1) });
                    break;
                // 右Z形
                case E_DrawType.Right_ZShape:
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(2, 0), new Position(2, 1) });
                    bolcks.Add(new Position[] { new Position(-2, 1), new Position(0, 1), new Position(2, 0) });
                    bolcks.Add(new Position[] { new Position(-2, -1), new Position(-2, 0), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(-2, 0), new Position(0, -1), new Position(2, -1) });
                    break;
                // 左L形
                case E_DrawType.Left_LShape:
                    bolcks.Add(new Position[] { new Position(-2, -1), new Position(0, -1), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(-2, 0), new Position(2, -1), new Position(2, 0) });
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(0, 1), new Position(2, 1) });
                    bolcks.Add(new Position[] { new Position(-2, 1), new Position(-2, 0), new Position(2, 0) });

                    break;
                // 右L形
                case E_DrawType.Right_LShape:
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(2, -1), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(-2, 0), new Position(2, 0), new Position(2, 1) });
                    bolcks.Add(new Position[] { new Position(0, -1), new Position(-2, 1), new Position(0, 1) });
                    bolcks.Add(new Position[] { new Position(-2, -1), new Position(-2, 0), new Position(2, 0) });
                    break;
            }
        }

        /// <summary>
        /// 通过索引获取方块坐标信息
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public Position[] this[int index]
        {
            get
            {
                if (index < 0 || index >= bolcks.Count)
                {
                    throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range.");
                }
                return bolcks[index]; // 返回指定索引的方块坐标信息
            }
        }

        /// <summary>
        /// 获取当前方块坐标信息的数量
        /// </summary>
        public int Count { get => bolcks.Count; }
    }
}